import unittest
import logging
import tempfile

import os

from pkgr.tests.mockrepository import MockRepository
from pkgr.pkgr import Pkgr
from pkgr.repos.rpm import RepoRepomd

logger = logging.getLogger('pkgr.test.test_pkgr')

class PkgrTestCase(unittest.TestCase):
    def setUp(self):
        logger.debug('Setting up mock repo...')
        self.cachedir = tempfile.mkdtemp()
        self.installroot = tempfile.mkdtemp()
        self.repo = MockRepository()
        self.repo.open()
        self.load_new_pkgr()
        
    def tearDown(self):
        #shutil.rmtree(self.cachedir)
       # shutil.rmtree(self.installroot)
        pass
    
    def load_new_pkgr(self):
            
        self.pkgr = pkgr = Pkgr()
        pkgr.set_arch(os.uname()[4])
        pkgr.set_cache_dir(self.cachedir)
        pkgr.set_root(self.installroot)
        pool = pkgr.get_solv_pool()
        sysrepo = pkgr.get_sysrepo()
        
        repoattr = {
            'enabled': True,
            'priority': 99,
            'type': 'rpmmd',
            'metadata_expire': 0
        }
        
        r = RepoRepomd('test', 'rpmmd', repoattr)
        r.set_url('url', self.repo.get_url())
        pkgr.add_repo(r)
        
        
        pkgr.post_repo_load()
        
    def dump_install_root(self):
        logger.info( "Install root contents: %s", str(os.listdir(self.installroot)))
        
        
if __name__ == '__main__':
    unittest.main()
    
    
    
    
    
